package com.cell.foodie.back.goods.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.cell.foodie.back.goods.entity.Goods;
import com.cell.foodie.back.goods.service.GoodsService;


@Controller
public class GoodsController {
	
	@Autowired
	GoodsService goodsService;
	/**
	 * 测试框架
	 * @param goods
	 * @return
	 */
	@RequestMapping("/bye")
	public ModelAndView getGoods(Goods goods) {
	  	
    List<Goods> goodsList = goodsService.getGoods(goods);
    
    ModelAndView mav = new ModelAndView();
    mav.setViewName("back/bye");
    mav.addObject("goodsList", goodsList);
    return mav;
  }
	
	/**
	 * 跳转添加页面
	 * @param goods
	 * @return
	 */
	@RequestMapping(value="/add",method=RequestMethod.GET)
	public String bookView(Model model) {
		return "back/goods_add";
	}
	/**
	 * 增加
	 */
	@ResponseBody
	@RequestMapping(value="/add",method=RequestMethod.POST)
	public String addGoods(@RequestBody Goods goods) {
		goodsService.add(goods);
		return "";
	}
	/**
	 * 跳转查询页面
	 * @param model
	 * @return
	 */
//	@RequestMapping(value="/get",method=RequestMethod.GET)
//	public String getViews(Model model) {
//		return "back/goods_select";
//	}
	/**
	 * 查询
	 */
	@ResponseBody
	@RequestMapping(value="/get",method=RequestMethod.POST)
	public List<Goods> getGoodss(@RequestBody Goods goods){
		List<Goods> goodsLists = goodsService.getGoodss(goods);		
		return goodsLists;
	}
	
	@RequestMapping(value="/get",method=RequestMethod.GET)
	public String getGoods(Model model,Goods goods) {
		List<Goods> goodsList = goodsService.getGoodss(goods);
		model.addAttribute(goodsList);
		return "back/goods_select";
	}
}
